package com.ies.dx.dex.file;

import com.ies.dx.util.Hex;
import com.ies.dx.util.Input;

public class proto_id_item extends dex_item
{
    private int shorty_idx;     //uint
    private int return_type_idx;//uint
    private int parameters_off; //uint
    
    private String shorty = null;
    private String return_type = null;
    private type_list parameters = null;
    
    public proto_id_item(dex_file file)
    {
        super(file);
    }
    
    public void readData(Input dis)
    {
        try
        {
            if (parameters_off == 0)
                return;
            dis.moveCursorTo(parameters_off);
            parameters = new type_list(mFile);
            parameters.read(dis);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    
    public void read(Input dis)
    {
        try
        {
            shorty_idx = dis.readInt();
            return_type_idx = dis.readInt();
            parameters_off = dis.readInt();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }        
    }

    public void show()
    {
//        System.out.println("[shorty_idx]            :" + shorty_idx + " (0x" + Hex.u4(shorty_idx) + ")");
//        System.out.println("[return_type_idx]       :" + return_type_idx + " (0x" + Hex.u4(return_type_idx) + ")");
//        System.out.println("[parameters_off]        :" + parameters_off + " (0x" + Hex.u4(parameters_off) + ")");
        System.out.println(getData());
    }
    
    public String getShorty()
    {
        if (shorty == null)
            shorty = mFile.getString(shorty_idx);
        return shorty;
    }
    
    public String getReturnType()
    {
        if (return_type == null)
            return_type = mFile.getString(return_type_idx);
        return return_type;
    }
    
    public String getParameters()
    {
        if (parameters == null)
            return "()";
        else
            return parameters.getData();
    }
    
    public String getData() 
    {
        return getParameters();
    }
}
